package Lab2ContainerAndIO;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class test {

	public static void main(String[] args) throws Exception {
		
		Lab2 lab2 = new Lab2();
		// 输入文件
		String fileName = "E:\\JavaHomework\\JavaAdvanced\\src\\Lab2ContainerAndIO\\了不起的盖茨比英文.txt";
		Map<String, Integer> map = new HashMap<>();
		
		String content = Lab2.txtReader(fileName);
		String[] words = lab2.splitContent(content);
		// 输出的文件
		String fileName2 =  "E:\\output.txt";
		File fileout = new File(fileName2);
		map = lab2.getStringFrequent(words);
		List<Map.Entry<String,Integer>> list = lab2.invert(map);
		Writer writer = null;
		try {
			Map.Entry<String, Integer> map2 = null;
			writer = new FileWriter(fileout);
			for(int i = 0; i < list.size(); i++) {
				map2 = list.get(i);
				writer.write(map2.getKey() + " " + map2.getValue() + "\n");
			}
		}catch (IOException e) {
			e.printStackTrace();
		}
	}
}